home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Developer & Web Development Tools / Inno Setup 5.2.3 / isetup-5.2.3.exe / {app} / Examples / CodeAutomation.iss (.txt) < prev    next >
Encoding:
Inno Setup Script  |  2006-10-03  |  8.1 KB  |  191 lines

  1. ; -- CodeAutomation.iss --
  2. ; This script shows how to use the COM Automation object support.
  3. [Setup]
  4. AppName=My Program
  5. AppVerName=My Program version 1.5
  6. CreateAppDir=no
  7. DisableProgramGroupPage=yes
  8. DefaultGroupName=My Program
  9. UninstallDisplayIcon={app}\MyProg.exe
  10. OutputDir=userdocs:Inno Setup Examples Output
  11. [Code]
  12. {--- SQLDMO ---}
  13. const
  14.   SQLServerName = 'localhost';
  15.   SQLDMOGrowth_MB = 0;
  16. procedure SQLDMOButtonOnClick(Sender: TObject);
  17.   SQLServer, Database, DBFile, LogFile: Variant;
  18.   IDColumn, NameColumn, Table: Variant;
  19. begin
  20.   if MsgBox('Setup will now connect to Microsoft SQL Server ''' + SQLServerName + ''' via a trusted connection and create a database. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  21.     Exit;
  22.   { Create the main SQLDMO COM Automation object }
  23.   try
  24.     SQLServer := CreateOleObject('SQLDMO.SQLServer');
  25.   except
  26.     RaiseException('Please install Microsoft SQL server connectivity tools first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
  27.   end;
  28.   { Connect to the Microsoft SQL Server }
  29.   SQLServer.LoginSecure := True;
  30.   SQLServer.Connect(SQLServerName);
  31.   MsgBox('Connected to Microsoft SQL Server ''' + SQLServerName + '''.', mbInformation, mb_Ok);
  32.   { Setup a database }
  33.   Database := CreateOleObject('SQLDMO.Database');
  34.   Database.Name := 'Inno Setup';
  35.   DBFile := CreateOleObject('SQLDMO.DBFile');
  36.   DBFile.Name := 'ISData1';
  37.   DBFile.PhysicalName := 'c:\program files\microsoft sql server\mssql\data\IS.mdf';
  38.   DBFile.PrimaryFile := True;
  39.   DBFile.FileGrowthType := SQLDMOGrowth_MB;
  40.   DBFile.FileGrowth := 1;
  41.   Database.FileGroups.Item('PRIMARY').DBFiles.Add(DBFile);
  42.   LogFile := CreateOleObject('SQLDMO.LogFile');
  43.   LogFile.Name := 'ISLog1';
  44.   LogFile.PhysicalName := 'c:\program files\microsoft sql server\mssql\data\IS.ldf';
  45.   Database.TransactionLog.LogFiles.Add(LogFile);
  46.   { Add the database }
  47.   SQLServer.Databases.Add(Database);
  48.   MsgBox('Added database ''' + Database.Name + '''.', mbInformation, mb_Ok);
  49.   { Setup some columns }
  50.   IDColumn := CreateOleObject('SQLDMO.Column');
  51.   IDColumn.Name := 'id';
  52.   IDColumn.Datatype := 'int';
  53.   IDColumn.Identity := True;
  54.   IDColumn.IdentityIncrement := 1;
  55.   IDColumn.IdentitySeed := 1;
  56.   IDColumn.AllowNulls := False;
  57.   NameColumn := CreateOleObject('SQLDMO.Column');
  58.   NameColumn.Name := 'name';
  59.   NameColumn.Datatype := 'varchar';
  60.   NameColumn.Length := '64';
  61.   NameColumn.AllowNulls := False;
  62.   { Setup a table }
  63.   Table := CreateOleObject('SQLDMO.Table');
  64.   Table.Name := 'authors';
  65.   Table.FileGroup := 'PRIMARY';
  66.   { Add the columns and the table }
  67.   Table.Columns.Add(IDColumn);
  68.   Table.Columns.Add(NameColumn);
  69.   Database.Tables.Add(Table);
  70.   MsgBox('Added table ''' + Table.Name + '''.', mbInformation, mb_Ok);
  71. {--- IIS ---}
  72. const
  73.   IISServerName = 'localhost';
  74.   IISServerNumber = '1';
  75.   IISURL = 'http://127.0.0.1';
  76. procedure IISButtonOnClick(Sender: TObject);
  77.   IIS, WebSite, WebServer, WebRoot, VDir: Variant;
  78.   ErrorCode: Integer;
  79. begin
  80.   if MsgBox('Setup will now connect to Microsoft IIS Server ''' + IISServerName + ''' and create a virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  81.     Exit;
  82.   { Create the main IIS COM Automation object }
  83.   try
  84.     IIS := CreateOleObject('IISNamespace');
  85.   except
  86.     RaiseException('Please install Microsoft IIS first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
  87.   end;
  88.   { Connect to the IIS server }
  89.   WebSite := IIS.GetObject('IIsWebService', IISServerName + '/w3svc');
  90.   WebServer := WebSite.GetObject('IIsWebServer', IISServerNumber);
  91.   WebRoot := WebServer.GetObject('IIsWebVirtualDir', 'Root');
  92.   { (Re)create a virtual dir }
  93.   try
  94.     WebRoot.Delete('IIsWebVirtualDir', 'innosetup');
  95.     WebRoot.SetInfo();
  96.   except
  97.   end;
  98.   VDir := WebRoot.Create('IIsWebVirtualDir', 'innosetup');
  99.   VDir.AccessRead := True;
  100.   VDir.AppFriendlyName := 'Inno Setup';
  101.   VDir.Path := 'C:\inetpub\innosetup';
  102.   VDir.AppCreate(True);
  103.   VDir.SetInfo();
  104.   MsgBox('Created virtual directory ''' + VDir.Path + '''.', mbInformation, mb_Ok);
  105.   { Write some html and display it }
  106.   if MsgBox('Setup will now write some HTML and display the virtual directory. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  107.     Exit;
  108.   ForceDirectories(VDir.Path);
  109.   SaveStringToFile(VDir.Path + '/index.htm', '<html><body>Inno Setup rocks!</body></html>', False);
  110.   if not ShellExec('open', IISURL + '/innosetup/index.htm', '', '', SW_SHOWNORMAL, ewNoWait, ErrorCode) then
  111.     MsgBox('Can''t display the created virtual directory: ''' + SysErrorMessage(ErrorCode) + '''.', mbError, mb_Ok);
  112. {--- MSXML ---}
  113. const
  114.   XMLURL = 'http://cvs.jrsoftware.org/view/*checkout*/ishelp/isxfunc.xml';
  115.   XMLFileName = 'isxfunc.xml';
  116.   XMLFileName2 = 'isxfuncmodified.xml';
  117. procedure MSXMLButtonOnClick(Sender: TObject);
  118.   XMLHTTP, XMLDoc, NewNode, RootNode: Variant;
  119.   Path: String;
  120. begin
  121.   if MsgBox('Setup will now use MSXML to download XML file ''' + XMLURL + ''' and save it to disk.'#13#13'Setup will then load, modify and save this XML file. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  122.     Exit;
  123.   { Create the main MSXML COM Automation object }
  124.   try
  125.     XMLHTTP := CreateOleObject('MSXML2.ServerXMLHTTP');
  126.   except
  127.     RaiseException('Please install MSXML first.'#13#13'(Error ''' + GetExceptionMessage + ''' occurred)');
  128.   end;
  129.   { Download the XML file }
  130.   XMLHTTP.Open('GET', XMLURL, False);
  131.   XMLHTTP.Send();
  132.   Path := ExpandConstant('{src}\');
  133.   XMLHTTP.responseXML.Save(Path + XMLFileName);
  134.   MsgBox('Downloaded the XML file and saved it as ''' + XMLFileName + '''.', mbInformation, mb_Ok);
  135.   { Load the XML File }
  136.   XMLDoc := CreateOleObject('MSXML2.DOMDocument');
  137.   XMLDoc.async := False;
  138.   XMLDoc.resolveExternals := False;
  139.   XMLDoc.load(Path + XMLFileName);
  140.   if XMLDoc.parseError.errorCode <> 0 then
  141.     RaiseException('Error on line ' + IntToStr(XMLDoc.parseError.line) + ', position ' + IntToStr(XMLDoc.parseError.linepos) + ': ' + XMLDoc.parseError.reason);
  142.   MsgBox('Loaded the XML file.', mbInformation, mb_Ok);
  143.   { Modify the XML document }
  144.   NewNode := XMLDoc.createElement('isxdemo');
  145.   RootNode := XMLDoc.documentElement;
  146.   RootNode.appendChild(NewNode);
  147.   RootNode.lastChild.text := 'Hello, World';
  148.   { Save the XML document }
  149.   XMLDoc.Save(Path + XMLFileName2);
  150.   MsgBox('Saved the modified XML as ''' + XMLFileName2 + '''.', mbInformation, mb_Ok);
  151. {--- Word ---}
  152. procedure WordButtonOnClick(Sender: TObject);
  153.   Word: Variant;
  154. begin
  155.   if MsgBox('Setup will now check whether Microsoft Word is running. Do you want to continue?', mbInformation, mb_YesNo) = idNo then
  156.     Exit;
  157.   { Try to get an active Word COM Automation object }
  158.   try
  159.     Word := GetActiveOleObject('Word.Application');
  160.   except
  161.   end;
  162.   if VarIsEmpty(Word) then
  163.     MsgBox('Microsoft Word is not running.', mbInformation, mb_Ok)
  164.   else
  165.     MsgBox('Microsoft Word is running.', mbInformation, mb_Ok)
  166. {---}
  167. procedure CreateButton(ALeft, ATop: Integer; ACaption: String; ANotifyEvent: TNotifyEvent);
  168. begin
  169.   with TButton.Create(WizardForm) do begin
  170.     Left := ALeft;
  171.     Top := ATop;
  172.     Width := WizardForm.CancelButton.Width;
  173.     Height := WizardForm.CancelButton.Height;
  174.     Caption := ACaption;
  175.     OnClick := ANotifyEvent;
  176.     Parent := WizardForm.WelcomePage;
  177.   end;
  178. procedure InitializeWizard();
  179.   Left, Top, TopInc: Integer;
  180. begin
  181.   Left := WizardForm.WelcomeLabel2.Left;
  182.   TopInc := WizardForm.CancelButton.Height + 8;
  183.   Top := WizardForm.WelcomeLabel2.Top + WizardForm.WelcomeLabel2.Height - 4*TopInc;
  184.   CreateButton(Left, Top, '&SQLDMO...', @SQLDMOButtonOnClick);
  185.   Top := Top + TopInc;
  186.   CreateButton(Left, Top, '&IIS...', @IISButtonOnClick);
  187.   Top := Top + TopInc;
  188.   CreateButton(Left, Top, '&MSXML...', @MSXMLButtonOnClick);
  189.   Top := Top + TopInc;
  190.   CreateButton(Left, Top, '&Word...', @WordButtonOnClick);
  191.